#include <workflow/WFFacilities.h>
#include <workflow/WFTaskFactory.h>
#include <ppconsul/ppconsul.h>
#include <iostream>
#include <54func.h>
using std::cout;
static WFFacilities::WaitGroup WaitGroup(1);
void handler(int signum){
    WaitGroup.done();
}
using namespace ppconsul;
void timerCallback(WFTimerTask *timerTask){
    cout << "now = " << time(nullptr) << "\n";
    agent::Agent *pagent = (agent::Agent *)timerTask->user_data;
    pagent->servicePass("SignupService1");
    WFTimerTask * nextTask = WFTaskFactory::create_timer_task(9,0,timerCallback);
    nextTask->user_data = pagent;
    series_of(timerTask)->push_back(nextTask);
}
int main(){
    signal(SIGINT,handler);
    Consul consul("127.0.0.1:8500",ppconsul::kw::dc = "dc1");
    agent::Agent agent(consul);
    agent.registerService(
                          agent::kw::name = "SignupService1",
                          agent::kw::address = "127.0.0.1",
                          agent::kw::id = "SignupService1",
                          agent::kw::port = 1412,
                          agent::kw::check = agent::TtlCheck(std::chrono::seconds(10))
                         );
    agent.servicePass("SignupService1");
    WFTimerTask * timerTask = 
    WFTaskFactory::create_timer_task(9,0,timerCallback);
    timerTask->user_data = &agent;
    timerTask->start();
    WaitGroup.wait();
}
